import { swagger } from '@elysiajs/swagger';

import { config } from '@/config';
import { getServiceUrl } from '@/config/utils';

/**
 * 创建 Swagger 配置
 */
export function createSwaggerConfig() {
  const { internal, external } = getServiceUrl();

  return swagger({
    scalarCDN:
      'https://cdnjs.cloudflare.com/ajax/libs/scalar-api-reference/1.25.103/standalone.min.js',
    documentation: {
      info: {
        title: config.swagger.title,
        version: config.swagger.version,
        description: config.swagger.description,
      },
      servers:
        internal !== external
          ? [
              {
                url: external,
                description: '服务器 URL',
              },
              {
                url: internal,
                description: '服务器内部 URL',
              },
            ]
          : [
              {
                url: external,
                description: '服务器 URL',
              },
            ],
    },
    path: config.swagger.path,
  });
}
